# SUR Mods, supp. material #

MFQ20 <- read.table(file.choose(), header = TRUE)

MFQ20$Party.cat <- NA
MFQ20$Party.cat[MFQ20$Party <= 3] <- "Democrat"
MFQ20$Party.cat[MFQ20$Party == 4] <- "Independent"
MFQ20$Party.cat[MFQ20$Party >= 5] <- "Republican"

MFQ20$Ideol.cat <- NA
MFQ20$Ideol.cat[MFQ20$Ideol <= 3] <- "Liberal"
MFQ20$Ideol.cat[MFQ20$Ideol == 4] <- "Moderate"
MFQ20$Ideol.cat[MFQ20$Ideol >= 5] <- "Conservative"

# Measures for Appendix #
MFQ20$HarmTotal.2 <- ((MFQ20$Harm1 + MFQ20$Harm2 + MFQ20$Harm3 + 
                         MFQ20$Harm4) - 4)/20
MFQ20$FairTotal.2 <- ((MFQ20$Fair1 + MFQ20$Fair2 + MFQ20$Fair3 + 
                         MFQ20$Fair4) - 4)/20
MFQ20$IngroupTotal.2 <- ((MFQ20$Ingroup1 + MFQ20$Ingroup2 + MFQ20$Ingroup3 +
                            MFQ20$Ingroup4) - 4)/20
MFQ20$AuthTotal.2 <- ((MFQ20$Auth1 + MFQ20$Auth2 + MFQ20$Auth3 + 
                         MFQ20$Auth4) - 4)/20
MFQ20$PureTotal.2 <- ((MFQ20$Pure1 + MFQ20$Pure2 + MFQ20$Pure3 +
                         MFQ20$Pure4) - 4)/20

# Using SystemFit package to fit mods #
library(systemfit)

# Dems First #
DemDataParty <- MFQ20[MFQ20$Party.cat == "Democrat" & 
                        MFQ20$Treatment != "Ideol",]

vars <- c("HarmTotal.1", "FairTotal.1", "IngroupTotal.1", "AuthTotal.1",
          "PureTotal.1", "Treatment")

DemDataParty <- DemDataParty[vars]
DemDataParty <- na.omit(DemDataParty)

DemDataParty$P <- ifelse(DemDataParty$Treatment == "Party", 1, 0)
DemDataParty$PI <- ifelse(DemDataParty$Treatment == "P + I", 1, 0)

Harm1 <- HarmTotal.2 ~ P + PI
Fair1 <- FairTotal.2 ~ P + PI
Ingroup1 <- IngroupTotal.2 ~ P + PI
Auth1 <- AuthTotal.2 ~ P + PI
Pure1 <- PureTotal.2 ~ P + PI

SURDems1 <- systemfit(list(HarmReg1 = Harm1, FairReg1 = Fair1, IngroupReg1 = Ingroup1,
                           AuthReg1 = Auth1, PureReg1 = Pure1), 
                      data = DemDataParty, method = "SUR")
summary(SURDems1)


linearHypothesis(SURDems1, "HarmReg_P - FairReg_P = 0")
linearHypothesis(SURDems1, "-HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURDems1, "HarmReg_P - IngroupReg_P = 0")
linearHypothesis(SURDems1, "HarmReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURDems1, "HarmReg_P - AuthReg_P = 0")
linearHypothesis(SURDems1, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURDems1, "HarmReg_P - PureReg_P = 0")
linearHypothesis(SURDems1, "HarmReg_PI - PureReg_PI = 0") # Sig @ .01


linearHypothesis(SURDems1, "FairReg_P - IngroupReg_P = 0")
linearHypothesis(SURDems1, "-FairReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURDems1, "FairReg_P- AuthReg_P = 0")
linearHypothesis(SURDems1, "-FairReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURDems1, "FairReg_P - PureReg_P = 0") # Sig @ .10
linearHypothesis(SURDems1, "-FairReg_PI - PureReg_PI = 0") # Sig @ .01


linearHypothesis(SURDems1, "IngroupReg_P - AuthReg_P = 0")
linearHypothesis(SURDems1, "IngroupReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURDems1, "IngroupReg_P - PureReg_P = 0") # Sig @ .10
linearHypothesis(SURDems1, "IngroupReg_PI - PureReg_PI = 0") # Sig @ .01


linearHypothesis(SURDems1, "AuthReg_P - PureReg_P = 0")
linearHypothesis(SURDems1, "AuthReg_PI - PureReg_PI = 0")


########
# Libs #
########

LibDataParty <- MFQ20[MFQ20$Ideol.cat == "Liberal" & 
                        MFQ20$Treatment != "Party",]

vars <- c("Treatment", "HarmTotal.2", "FairTotal.2",
          "IngroupTotal.2", "AuthTotal.2", "PureTotal.2")

LibDataParty <- LibDataParty[vars]
LibDataParty <- na.omit(LibDataParty)


LibDataParty$I <- ifelse(LibDataParty$Treatment == "Ideol", 1, 0)
LibDataParty$PI <- ifelse(LibDataParty$Treatment == "P + I", 1, 0)

Harm1 <- HarmTotal.2 ~ I + PI
Fair1 <- FairTotal.2 ~ I + PI
Ingroup1 <- IngroupTotal.2 ~ I + PI
Auth1 <- AuthTotal.2 ~ I + PI
Pure1 <- PureTotal.2 ~ I + PI


SURLibs1 <- systemfit(list(HarmReg1 = Harm1, FairReg1 = Fair1, IngroupReg1 = Ingroup1,
                          AuthReg1 = Auth1, PureReg1 = Pure1), 
                     data = LibDataParty, method = "SUR")
summary(SURLibs1)


linearHypothesis(SURLibs1, "HarmReg_I - FairReg_I = 0")
linearHypothesis(SURLibs1, "-HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURLibs1, "HarmReg_I - IngroupReg_I = 0")
linearHypothesis(SURLibs1, "HarmReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURLibs1, "HarmReg_I - AuthReg_I = 0")
linearHypothesis(SURLibs1, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURLibs1, "HarmReg_I - PureReg_I = 0")
linearHypothesis(SURLibs1, "HarmReg_PI - PureReg_PI = 0") # Sig @ .05


linearHypothesis(SURLibs1, "FairReg_I - IngroupReg_I = 0")
linearHypothesis(SURLibs1, "-FairReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURLibs1, "FairReg_I - AuthReg_I = 0")
linearHypothesis(SURLibs1, "-FairReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURLibs1, "FairReg_I - PureReg_I = 0") 
linearHypothesis(SURLibs1, "-FairReg_PI - PureReg_PI = 0") # Sig @ .10


linearHypothesis(SURLibs1, "IngroupReg_I - AuthReg_I = 0") 
linearHypothesis(SURLibs1, "IngroupReg_PI - AuthReg_PI = 0") # Sig @ .10


linearHypothesis(SURLibs1, "IngroupReg_I - PureReg_I = 0")
linearHypothesis(SURLibs1, "IngroupReg_PI - PureReg_PI = 0")


linearHypothesis(SURLibs1, "AuthReg_I - PureReg_I = 0")
linearHypothesis(SURLibs1, "AuthReg_PI - PureReg_PI = 0")



##############
# Repubs #####
##############

RepDataParty <- MFQ20[MFQ20$Party.cat == "Republican" & 
                        MFQ20$Treatment != "Ideol",]

vars <- c("Treatment", "HarmTotal.2", "FairTotal.2",
          "IngroupTotal.2", "AuthTotal.2", "PureTotal.2")

RepDataParty <- RepDataParty[vars]
RepDataParty <- na.omit(RepDataParty)

RepDataParty$P <- ifelse(RepDataParty$Treatment == "Party", 1, 0)
RepDataParty$PI <- ifelse(RepDataParty$Treatment == "P + I", 1, 0)


Harm1 <- HarmTotal.2 ~ P + PI
Fair1 <- FairTotal.2 ~ P + PI
Ingroup1 <- IngroupTotal.2 ~ P + PI
Auth1 <- AuthTotal.2 ~ P + PI
Pure1 <- PureTotal.2 ~ P + PI


SURReps1 <- systemfit(list(HarmReg1 = Harm1, FairReg1 = Fair1, IngroupReg1 = Ingroup1,
                          AuthReg1 = Auth1, PureReg1 = Pure1), 
                     data = RepDataParty, method = "SUR")
summary(SURReps1)


linearHypothesis(SURReps1, "HarmReg_P - FairReg_P = 0")
linearHypothesis(SURReps1, "HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURReps1, "-HarmReg_P - IngroupReg_P = 0")
linearHypothesis(SURReps1, "-HarmReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURReps1, "-HarmReg_P - AuthReg_P = 0")
linearHypothesis(SURReps1, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURReps1, "HarmReg_P - PureReg_P = 0")
linearHypothesis(SURReps1, "HarmReg_PI - PureReg_PI = 0") # Sig @ .10


linearHypothesis(SURReps1, "-FairReg_P - IngroupReg_P = 0")
linearHypothesis(SURReps1, "-FairReg_PI - IngroupReg_PI = 0")


linearHypothesis(SURReps1, "-FairReg_P - AuthReg_P = 0")
linearHypothesis(SURReps1, "FairReg_PI - AuthReg_PI = 0") # Sig @ .05


linearHypothesis(SURReps1, "FairReg_P - PureReg_P = 0")
linearHypothesis(SURReps1, "FairReg_PI - PureReg_PI = 0") # Sig @ .10


linearHypothesis(SURReps1, "IngroupReg_P - AuthReg_P = 0")
linearHypothesis(SURReps1, "-IngroupReg_PI - AuthReg_PI = 0")


linearHypothesis(SURReps1, "-IngroupReg_P - PureReg_P = 0") 
linearHypothesis(SURReps1, "-IngroupReg_PI - PureReg_PI = 0")


linearHypothesis(SURReps1, "-AuthReg_P - PureReg_P = 0") 
linearHypothesis(SURReps1, "AuthReg_PI - PureReg_PI = 0")


#################
# Conservatives #
#################

ConsDataParty <- MFQ20[MFQ20$Ideol.cat == "Conservative" & 
                         MFQ20$Treatment != "Party",]

vars <- c("Treatment", "HarmTotal.2", "FairTotal.2",
          "IngroupTotal.2", "AuthTotal.2", "PureTotal.2")

ConsDataParty <- ConsDataParty[vars]
ConsDataParty <- na.omit(ConsDataParty)

ConsDataParty$I <- ifelse(ConsDataParty$Treatment == "Ideol", 1, 0)
ConsDataParty$PI <- ifelse(ConsDataParty$Treatment == "P + I", 1, 0)

Harm1 <- HarmTotal.2 ~ I + PI
Fair1 <- FairTotal.2 ~ I + PI
Ingroup1 <- IngroupTotal.2 ~ I + PI
Auth1 <- AuthTotal.2 ~ I + PI
Pure1 <- PureTotal.2 ~ I + PI


SURCons1 <- systemfit(list(HarmReg1 = Harm1, FairReg1 = Fair1, IngroupReg1 = Ingroup1,
                          AuthReg1 = Auth1, PureReg1 = Pure1), 
                     data = ConsDataParty, method = "SUR")
summary(Cons1)

linearHypothesis(SURCons1, "HarmReg_I - FairReg_I = 0")
linearHypothesis(SURCons1, "HarmReg_PI - FairReg_PI = 0")


linearHypothesis(SURCons1, "-HarmReg_I - IngroupReg_I = 0")
linearHypothesis(SURCons1, "-HarmReg_PI - IngroupReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons1, "HarmReg_I - AuthReg_I = 0") # Sig @ .01
linearHypothesis(SURCons1, "HarmReg_PI - AuthReg_PI = 0") # Sig @ .01


linearHypothesis(SURCons1, "HarmReg_I - PureReg_I = 0") # Sig @ .05
linearHypothesis(SURCons1, "HarmReg_PI - PureReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons1, "-FairReg_I - IngroupReg_I = 0")
linearHypothesis(SURCons1, "-FairReg_PI - IngroupReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons1, "FairReg_I - AuthReg_I = 0") # Sig @ .01
linearHypothesis(SURCons1, "FairReg_PI - AuthReg_PI = 0") # Sig @ .01


linearHypothesis(SURCons1, "FairReg_I - PureReg_I = 0") # Sig @ .05
linearHypothesis(SURCons1, "FairReg_PI - PureReg_PI = 0") # Sig @ .05


linearHypothesis(SURCons1, "-IngroupReg_I - AuthReg_I = 0") 
linearHypothesis(SURCons1, "-IngroupReg_PI - AuthReg_PI = 0")


linearHypothesis(SURCons1, "-IngroupReg_I - PureReg_I = 0")
linearHypothesis(SURCons1, "-IngroupReg_PI - PureReg_PI = 0")


linearHypothesis(SURCons1, "AuthReg_I - PureReg_I = 0")
linearHypothesis(SURCons1, "AuthReg_PI - PureReg_PI = 0")


